
__app.define("common_VM_Extend.js", function () {
  var common_VM_Extend = {
    afterRequest: function(reponse) {
      if(reponse.url.indexOf('archives/product/getTop3HotProducts?isArchive=1&pageSize=6')>-1) {
        // console.log("zxc",reponse)
        editPrice(reponse.data.data)
      }
      if(reponse.url.indexOf('goods/promotion/getAllScopePromotions')>-1) {
        if(reponse.data.data.combinationPromotion.length != 0){
          reponse.data.data.combinationPromotion.forEach((item) => {
            if(item.lsGroups.length != 0) {
              item.lsGroups.forEach((obj) => {
                if(obj.lsProes.length != 0) {
                    salePrice(obj.lsProes)
                }
              })
            }
          })
        }
        if(reponse.data.data.productPromotion.length != 0) {
          reponse.data.data.productPromotion.forEach((item) => {
            if(item.products.length != 0){
              item.products.forEach((obj) => {
                getPrice(obj)
              })
            }
          })
        }
        // if(reponse.data.data.selectFreePromotion.length != 0) {
        //   reponse.data.data.selectFreePromotion.forEach((item) => {
        //     if(item.products.length != 0){
        //       item.products.forEach((obj) => {
        //         list.push(obj)
        //       })
        //     }
        //   })
        // }
      }
    },
  };
  return common_VM_Extend;
});
function editPrice(data) { 
  let obj = {
    customer: window.__app.mainV.$store.getters.currentUser.agentId,
    deliveryMethod: '自提',
    receiveAddress: '',
    productDetail: [],
  }
  data.forEach(element => {
    let product = {
      productCode: element.code,
      productId: element.id,
      org: element.saleOrgId,
      priceQty: 1,
      productUnitId: element.mainUnit.id,
      currency: '1655486829428736015',
      stockId: ''
    }
    obj.productDetail.push(product)
  });
  const url = 'https://saas.hlhs-bip.com/iuap-api-gateway/ajxbewdh/AcquisitionPrice/GetPriceAndFreight/pricing/acquisitionPrice?appKey=a4dc65b0fbab4f68a56e8054999a2ab3'
  __app.ajax({
    type: "POST",
    data: obj,
    url: url,
    success: (res) => {
      data.forEach((item) => {
        item.fSalePrice = res[item.id].price
      })
      // debugger
    },
    error: function (error) {
      console.log(error)
    }
  })
}
function salePrice(data) {
  let obj = {
    customer: window.__app.mainV.$store.getters.currentUser.agentId,
    deliveryMethod: '自提',
    receiveAddress: '',
    productDetail: [],
  }
  data.forEach(element => {
    let product = {
      productCode: element.oProduct.cCode,
      productId: element.oProduct.id,
      org: element.oProduct.saleOrgId,
      priceQty: 1,
      productUnitId: element.oProduct.mainUnit.id,
      currency: '1655486829428736015',
      stockId: ''
    }
    obj.productDetail.push(product)
  });
  const url = 'https://saas.hlhs-bip.com/iuap-api-gateway/ajxbewdh/AcquisitionPrice/GetPriceAndFreight/pricing/acquisitionPrice?appKey=a4dc65b0fbab4f68a56e8054999a2ab3'
  __app.ajax({
    type: "POST",
    data: obj,
    url: url,
    success: (res) => {
      data.forEach((item) => {
        item.oSku.fOriginalSalePrice = res[item.oProduct.id].price
      })
      // debugger
    },
    error: function (error) {
      console.log(error)
    }
  })
}
function getPrice(data) { 
  let obj = {
    customer: window.__app.mainV.$store.getters.currentUser.agentId,
    deliveryMethod: '自提',
    receiveAddress: '',
    productDetail: [{
      productCode: data.code,
      productId: data.id,
      org: data.saleOrgId,
      priceQty: 1,
      productUnitId: data.mainUnit.id,
      currency: '1655486829428736015',
      stockId: ''
    }],
  }
  const url = 'https://saas.hlhs-bip.com/iuap-api-gateway/ajxbewdh/AcquisitionPrice/GetPriceAndFreight/pricing/acquisitionPrice?appKey=a4dc65b0fbab4f68a56e8054999a2ab3'
  __app.ajax({
    type: "POST",
    data: obj,
    url: url,
    success: (res) => {
      data.salePrice = res[data.id].price
      // debugger
    },
    error: function (error) {
      console.log(error)
    }
  })
}